﻿using System.Windows.Input;
using Avalonia.Exusiai.Editor.Models;
using Core.ECS;
using ReactiveUI;

namespace Avalonia.Exusiai.Editor.ViewModels;

public class BehaviorItemViewModel:ViewModelBase
{
    private bool _isEdit;
    private string _name;
    private string _oldName="New Behavior";
    public bool IsEdit
    {
        get => _isEdit;
        set => this.RaiseAndSetIfChanged(ref _isEdit, value);
    }
    public string Name
    {
        get => _name;
        set => this.RaiseAndSetIfChanged(ref _name, value);
    }
    public ICommand EditCommand { get; set; }
    public BehaviorItemViewModel()
    {
        EditCommand = ReactiveCommand.Create(Edit);
    }

    private void Edit()
    {
        if (IsEdit)
        {
            ObjectInspectionViewModel.Actor.BehaviorsName.Add(Name);
            ObjectInspectionViewModel.Actor.BehaviorsName.Remove(_oldName);
        }
        else
        {
            _oldName = Name;
        }
        IsEdit = !IsEdit;
    }


    public BehaviorItemViewModel(Behavior behavior)
    {
        IsEdit=behavior.IsEdit;
        Name=behavior.Name;
    }
    public Behavior GetBehaviorItem()
    {
        return new Behavior()
        {
            IsEdit = IsEdit,
            Name = Name
        };
    }
}